
import re
from pyjon import defs as js_defs

printError = js_defs.printError
printNotice = js_defs.printNotice

# JooScript tokens
jooTokens = dict(enumerate((

    # Dictionary
    "=>",
    "HASHMAP_INIT", "HASH_SEEK", 
    "ROLE_ENTRY",

    # New keywords
    "class", "package", "import",
    "as", "role", "use",
    
    # Context-objects
    "self", "root", "unit", "glob",

    # Event syntax
    "when", "once", "dispatch", "dismiss",
    "on", "over", "to", "from",

    # Logical operators
    #"and", "or", "not",
    "is",

    # Null object
    "none"

    ), js_defs.tokensLen))

keywords = js_defs.keywords.copy()
tokenIds = js_defs.tokenIds #js_defs.tokenIds.copy()
tokens = js_defs.tokens #js_defs.tokens.copy()
opTypeNames = js_defs.opTypeNames #[pair for pair in js_defs.opTypeNames]
opTypeNames.append(("=>", "HASHMAP_ENTRY"))

# JooScript tokens
for i, t in jooTokens.copy().iteritems():
    if re.match(r'^[a-z]', t):
        const_name = t.upper()
        keywords[t] = i
    elif re.match(r'^\W', t):
        const_name = dict(opTypeNames)[t]
    else:
        const_name = t
    globals()[const_name] = i
    tokenIds[const_name] = i
    tokens[t] = i
    tokens[i] = t

deprecatedKeywords = [ "null", "new", "switch", "case", "default", 
                       "var", "const", "typeof" ]
for k in deprecatedKeywords:
    del keywords[k]

def map(obj):
    for const_name, i in tokenIds.iteritems():
        obj[const_name] = i
